<?php
class Order_tuikuanModel extends Model {

	public function get_primary_key() {
		return $this->primary_key = 'id';
	}

	public function set($id, $data) {
		$id = intval($id);
	    if ($id) {
	        $this->update($data, 'id=' . $id);
	        return $id;
	    }
	    $this->insert($data);
	    if ($this->get_insert_id()) return $this->get_insert_id();
	    return false;
	}
	
	public function del($id) {
	    $this->delete('id=' . $id );
	}
	
	
	public function get_tuihuo_shop($id){

 $sql = "select s.id,s.number,s.price,s.ret_status,o.id as o_id,o.dingdanhao,c.title,c.thumb from ".$this->prefix."order_shop s "."
		 left join ".$this->prefix."order o on o.id=s.order_id "."
		 left join ".$this->prefix."content_1 c on c.id=s.shop_id "."
		 where s.id=$id";
	$res = $this->db->query($sql)->row_array();
	return $res;
	}
	
	
	
	public function getshop_num($id){
		$sql = "select number from ".$this->prefix."order_shop where id=$id";
		$res = $this->db->query($sql)->row_array();
		return $res['number'];
	}
	
	public function uporder_shop($id){
		$sql = "update ".$this->prefix."order_shop set ret_status=2 where id=$id";
		$this->db->query($sql);
	}
	
	
	
	//后台
	public function get_admin_list($where,$order,$limit,$ifcount=false){
		if($ifcount){
			$sql = "select count(ore.id) as total from ".$this->prefix . "order_ret ore "." 
					left join ".$this->prefix."member m on m.id=ore.member_id "."
					left join ".$this->prefix."order o on o.id=ore.order_id "."
					left join ".$this->prefix."order_shop os on os.id=ore.order_shop_id "."
					left join ".$this->prefix."content_1 c on c.id=os.shop_id "."
					where $where";
			$res = $this->db->query($sql)->row_array();
			return $res['total'];
		}
		$sql = "select ore.*,m.name as m_name,m.username as m_username,"."
				o.dingdanhao as o_dingdanhao,c.id as c_id,c.title as c_title,"."
				os.price as os_price from ".$this->prefix . "order_ret ore "."
				left join ".$this->prefix."member m on m.id=ore.member_id "."
				left join ".$this->prefix."order o on o.id=ore.order_id "."
				left join ".$this->prefix."order_shop os on os.id=ore.order_shop_id "."
				left join ".$this->prefix."content_1 c on c.id=os.shop_id "."
		        where $where order by $order limit $limit";
		$res = $this->db->query($sql)->result_array();
		return $res;
	}

    public function get_one($id){
        $sql = "select * from ".$this->prefix."order_tuikuan where order_id=$id";
        $res = $this->db->query($sql)->row_array();
        return $res;
    }
	
	
	
	


}